<?php

App::uses('PublicoController', 'Controller');

class SesionController extends PublicoController
{

    public function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allow();
    }

    public function Index()
    {
        $this->set('title', 'Acceder');
        $this->set('description', 'Panel para ingreso de usuarios');
    }

    public function Login()
    {
        if ($this->request->is('post'))
        {
            $rfc = $this->request->data['User']['user'];
            if (strlen($rfc) > 10)
            {
                /// Le quitamos la homoclave
                $this->request->data['User']['user'] = substr($rfc, 0, 10);
            }
            if ($this->Auth->login())
            {
                return $this->redirect($this->Auth->redirectUrl());
            }
        }
        $this->set('title', 'Acceder');
        $this->set('description', 'Panel para ingreso de usuarios');
    }

    public function Logout()
    {
        $this->Auth->logout();
        $this->set('title', 'Fin de sesión');
        $this->set('description', 'Tu sesión ha finalizado');
    }

    public function Bienvenido()
    {
        if (!$this->Auth->loggedIn())
        {
            $this->Auth->authError = false;
        }
        $this->set('title', 'Bienvenido');
        $this->set('description', 'Inicio de sesión');
    }

}
